package demo03;

import java.io.FileInputStream;
import java.io.ObjectInputStream;

public class Demo02ObjectInputStream {
    public static void main(String[] args) {
        try (ObjectInputStream objectInputStream = new ObjectInputStream( // 创建反序列化流对象
                new FileInputStream("file\\ObjectTxt\\object.txt"))) {
            Person person = (Person) objectInputStream.readObject(); // 读对象，读到的对象默认是Object类型，需要强转为对应对象的类型
            System.out.println(person); // Person [age=18, name=土司鸡, num=0]
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
